<?php

namespace app\service\admin;

use app\model\Common;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;

/**
 * 站点设置
 *
 * user ：Du
 * Date : 2022/3/24
 * Time : 10:11
 * Class WebsiteService
 * @package projects\services\admin
 */
class WebsiteService
{
    /**
     * 获取站点信息
     *
     * @return array|Model|null
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     * @author Du
     * @date 2021/3/29 17:22
     */
    public static function getWebsite()
    {
        $field = ['name', 'icon', 'desc', 'upload_size', 'copyright', 'domain'];
        $res = Common::getData(WebsiteTable, ['id' => 1], $field);
        $res['icon'] = imagePath($res['icon']);
        return $res;
    }

    /**
     * 修改数据
     * @param array $request
     * @return int
     * @throws DbException
     * @author Du
     * @date 2021/3/29 17:22
     */
    public static function updateWebsite(array $request): int
    {
        if (!$request['icon'] || $request['icon'] === '') {
            unset($request['icon']);
        }
        $request['update_time'] = time();
        return Common::updateData(WebsiteTable, ['id' => 1], $request);
    }
}